﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class Manage_User_list : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            this.bind();
        }
    }
    public void bind()
    {
        SqlConnection strcon = Class1.DBconnection();
        strcon.Open();
        SqlDataAdapter sda = new SqlDataAdapter("select * from tb_User order by id desc", strcon);
        DataSet ds = new DataSet();
        sda.Fill(ds, "tb_User");
        this.GridView1.DataSource = ds.Tables["tb_User"];
        this.GridView1.DataKeyNames = new string[] { "id" };
        this.GridView1.DataBind();
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.GridView1.PageIndex = e.NewPageIndex;
        this.bind();
    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string id = this.GridView1.DataKeys[e.RowIndex].Value.ToString();
        SqlConnection strcon = Class1.DBconnection();
        strcon.Open();
        SqlCommand scd = new SqlCommand("delete from tb_User where id=" + id, strcon);
        scd.ExecuteNonQuery();
        this.bind();
        strcon.Close();
    }
    protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {
        SqlConnection strcon = Class1.DBconnection();
        strcon.Open();
        string id = this.GridView1.DataKeys[e.NewSelectedIndex].Value.ToString();
        SqlCommand scd = new SqlCommand("select Auditing from tb_User where id=" + id, strcon);
        string Auditing = Convert.ToString(scd.ExecuteScalar());
        if (Auditing == "0")
        {
            Auditing = "1";
        }
        else
        {
            Auditing = "0";
        }
        scd.CommandText = "update tb_User set Auditing=" + Auditing + " where id=" + id;
        scd.ExecuteNonQuery();
        this.bind();
        strcon.Close();
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.Cells[4].Text == "0")
            {
                e.Row.Cells[4].Text = "未审核";
            }
            else
            {
                e.Row.Cells[4].Text = "<font color=red>已审核</font>";
            }
            ((LinkButton)(e.Row.Cells[6].Controls[0])).Attributes.Add("onclick", "return confirm('确定删除吗？')");
        }
    }
}
